package by.kniazhych.core.controllers.actions {
	
	/**
	 * ...
	 * @author Boutylin Mikhail
	 */
	
	import by.kniazhych.core.controllers.AbstractServerAction;
	import by.kniazhych.core.controllers.GameController;
	import by.kniazhych.core.events.GameEvent;
	import by.kniazhych.core.server.common.UserNotifycation;
	import by.kniazhych.core.view.game.notifycations.NotifycationFactory;
	import design.popups.GloryPopup;
	import design.popups.RokashPopup;
	import design.popups.ShahPopup;
	import design.popups.TronPopup;
	import design.popups.WinPopup;
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.setTimeout;
	
	
	
	public class NotifyUserAction extends AbstractServerAction{
		
		private var _message:String;
		private var _notification:DisplayObject;
		private static const _factory:NotifycationFactory = new NotifycationFactory();
		
		//_popups[GameState.CHOSE_FIGURE_STATE] = new PopupView(WinPopup);
		
		public function NotifyUserAction(target:GameController, message:String) {
			super(target);
			_message = message;
			_factory.addEventListener(NotifycationFactory.HIDE_LAST_ONE, _handleNotifycationClose);
		}
		
		override public function process():void {
			_notification = _factory.getPopup(_message);
			super._gameContainer.addChild(_notification);
			
		}
		
		private function _handleNotifycationClose(e:Event):void {
			_factory.removeEventListener(NotifycationFactory.HIDE_LAST_ONE, _handleNotifycationClose);
			super._gameContainer.removeChild(_notification);
			dispatchEvent(new GameEvent(GameEvent.ACTION_PROCESSED));
		}
		
	}
}
